package shop.common.utils;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;

public class ConvertUtil {
    private static final ObjectMapper mapper = new ObjectMapper();
    public static <T> T cast(Object obj, Class<T> targetClass){
        String string = null;
        T entity = null;
        try {
            string = mapper.writeValueAsString(obj);
            entity = mapper.readValue(string, targetClass);
        } catch (JsonProcessingException e) {
            throw new RuntimeException(e);
        }
        return entity;
    }
}